﻿Imports Infragistics.Win.Misc
Imports Infragistics.Win.UltraWinToolTip
Public Class ValidationsHelper
  Public Shared Function RequestFieldValidator(ByVal pControl As Control, ByVal pUltraValidator As UltraValidator, _
                                               ByVal pNombreCampo As String, Optional ByVal pPropertyToValidate As String = "Text", _
                                               Optional ByVal pUttmLabel As UltraToolTipManager = Nothing) As ValidationSettings

    Dim objValSett As ValidationSettings = pUltraValidator.GetValidationSettings(pControl)
    Try
      With objValSett
        .Reset()
        .IsRequired = True
        .RetainFocusOnError = False
        .ValidationTrigger = ValidationTrigger.OnPropertyValueChanged
        .ValidationPropertyName = pPropertyToValidate
        .NotificationSettings.Caption = "Campo """ & pNombreCampo & """ requerido."
        .NotificationSettings.Text = "El campo " & pNombreCampo & " debe ser ingresado ya que es obligatorio."
        .NotificationSettings.Action = NotificationAction.BalloonTip
      End With

      If pUttmLabel IsNot Nothing Then
        With pUttmLabel.GetUltraToolTip(pControl)
          .Enabled = Infragistics.Win.DefaultableBoolean.True
          .ToolTipText = "Campo " & pNombreCampo
          .ToolTipTitle = "Requerido"
        End With
      End If
      Return objValSett
    Catch ex As Exception
      Throw ex
    End Try

  End Function

  Public Shared Sub SetToolTip(ByVal pControl As Control, ByVal pUttmLabel As UltraToolTipManager, ByVal pNombreCampo As String, _
                               Optional ByVal pTituloCampo As String = "Opcional")
    With pUttmLabel.GetUltraToolTip(pControl)
      .Enabled = Infragistics.Win.DefaultableBoolean.True
      .ToolTipText = "Campo " & pNombreCampo
      .ToolTipTitle = pTituloCampo
    End With

  End Sub
End Class
